
import 'dart:async';

import 'package:flutter/services.dart';

class LocationUploadFlutter {
  static const MethodChannel _channel =
      const MethodChannel('location_upload_flutter');

  static Future<String?> get platformVersion async {
    final String? version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  ///设置Android和iOS的apikey，建议在weigdet初始化时设置<br>
  ///apiKey的申请请参考高德开放平台官网<br>
  ///Android端: https://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key<br>
  ///iOS端: https://lbs.amap.com/api/ios-location-sdk/guide/create-project/get-key<br>
  ///[androidKey] Android平台的key<br>
  ///[iosKey] ios平台的key<br>
  static void setApiKey(String androidKey, String iosKey) {
    _channel
        .invokeMethod('setApiKey', {'android': androidKey, 'ios': iosKey});
  }


  /*
  context是Context上下文2appId是String网络货运企业APP的唯一标识
  3appSecurity是String网络货运企业在省平台申请的接入安全码4
  enterpriseSenderCode是String网络货运企业在省平台申请的企业发送代码5
  environment是String环境:“debug”接入测试环境，“release”接入正式环境。
  6listener是OnResultListener返回结果回调函数
  */

  static Future<Map> auth(String appId, String appSecurity,
      String enterpriseSenderCode, String environment) async {
    // print("auth-map==${"appId": appId, "appSecurity": appSecurity,
    //     "enterpriseSenderCode": enterpriseSenderCode, "environment":environment
    //     }");
    print("appId == $appId, $appSecurity");
    return await _channel.invokeMethod('auth', {"appId": appId, "appSecurity": appSecurity,
      "enterpriseSenderCode": enterpriseSenderCode, "environment":environment
    });
  }

  ///开始运输
  /*
  1context是Context上下文
  2vehicleNumber是String车牌号
  3driverName是String司机姓名
  4remark否String备注
  5shippingNoteInfos是ShippingNoteInfo运单信息列表
  6listener是OnResultListener结果回调函数
   */
  static Future<Map> start(String vehicleNumber, String driverName, List shippingNoteInfos,
      String remark) async {
    return await _channel.invokeMethod("start", {"vehicleNumber": vehicleNumber, "driverName":driverName
    , "shippingNoteInfos": shippingNoteInfos, "remark":remark});
  }

  ///位置信息上报
  /*
  1context是Context上下文
  2vehicleNumber是String车牌号
  3driverName是String司机姓名
  4remark否String备注
  5shippingNoteInfos是ShippingNoteInfo运单信息列表
  6listener是OnResultListener结果回调函数
   */
  static Future<Map> send(String vehicleNumber, String driverName, List shippingNoteInfos,
      String remark) async {
    return await _channel.invokeMethod("send", {"vehicleNumber": vehicleNumber, "driverName":driverName
      , "shippingNoteInfos": shippingNoteInfos, "remark":remark});
  }

  ///暂停定位
  /*
  1context是Context上下文
  2vehicleNumber是String车牌号
  3driverName是String司机姓名
  4remark否String备注
  5shippingNoteInfos是ShippingNoteInfo运单信息列表
  6listener是OnResultListener结果回调函数
   */
  static Future<Map> pause(String vehicleNumber, String driverName, List shippingNoteInfos,
      String remark) async {
    return await _channel.invokeMethod("pause", {"vehicleNumber": vehicleNumber, "driverName":driverName
      , "shippingNoteInfos": shippingNoteInfos, "remark":remark});
  }

  ///重启定位
  /*
  1context是Context上下文
  2vehicleNumber是String车牌号
  3driverName是String司机姓名
  4remark否String备注
  5shippingNoteInfos是ShippingNoteInfo运单信息列表
  6listener是OnResultListener结果回调函数
   */
  static Future<Map> restart(String vehicleNumber, String driverName, List shippingNoteInfos,
      String remark) async {
    return await _channel.invokeMethod("restart", {"vehicleNumber": vehicleNumber, "driverName":driverName
      , "shippingNoteInfos": shippingNoteInfos, "remark":remark});
  }

  ///结束定位
  /*
  1context是Context上下文
  2vehicleNumber是String车牌号
  3driverName是String司机姓名
  4remark否String备注
  5shippingNoteInfos是ShippingNoteInfo运单信息列表
  6listener是OnResultListener结果回调函数
   */
  static Future<Map> stop(String vehicleNumber, String driverName, List shippingNoteInfos,
      String remark) async {
    return await _channel.invokeMethod("stop", {"vehicleNumber": vehicleNumber, "driverName":driverName
      , "shippingNoteInfos": shippingNoteInfos, "remark":remark});
  }

}
